package floatingactionbutton.zjitc.net.androidhomeworktab;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    TabLayout mTabLayout;
    ViewPager mViewPager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();


    }

    private void init() {
        mTabLayout=findViewById(R.id.tabs);
        mViewPager=findViewById(R.id.viewpager);
        List<String> titles=new ArrayList<>();
        titles.add("首页");
        titles.add("漫单");
        titles.add("漫圈");
        titles.add("画板");
        titles.add("新番");
        titles.add("漫板");
        titles.add("分类");
        for (int i = 0; i <titles.size() ; i++) {
            mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(i)));
        }

        List<View> list=new ArrayList<>();
        View view1 = getLayoutInflater().inflate(R.layout.view1, null, false);
        View view2=getLayoutInflater().inflate(R.layout.view2,null,false);
        View view3=getLayoutInflater().inflate(R.layout.view3,null,false);
        View view4=getLayoutInflater().inflate(R.layout.view4,null,false);
        View view5=getLayoutInflater().inflate(R.layout.view5,null,false);
        View view6=getLayoutInflater().inflate(R.layout.view6,null,false);
        View view7=getLayoutInflater().inflate(R.layout.view7,null,false);
        list.add(view1);
        list.add(view2);
        list.add(view3);
        list.add(view4);
        list.add(view5);
        list.add(view6);
        list.add(view7);

        MyPagerAdapter myPagerAdapter=new MyPagerAdapter(titles,list);
        mViewPager.setAdapter(myPagerAdapter);
//        mTabLayout.setupWithViewPager(mViewPager);
        mTabLayout.setupWithViewPager(mViewPager);

    }
}
